package com.example.pro1.service.lian.oldService;


import com.example.pro1.mapper.lian.oldMapper.rootMapperOld;
import com.example.pro1.entity.lian.oldPojo.rootOld;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Service
@Transactional
public class rootService {
    @Autowired
    rootMapperOld rootMapperOld;

    /*查询root信息*/
    public Integer getRootNums(){
        return rootMapperOld.getRootNums();
    }

    /*查询管理员信息*/
    public List<rootOld> getRootersInfo(Map<String,Object> map){
        if (map.containsKey("k") && map.containsKey("num")){
            map.put("k",Integer.parseInt((String) map.get("k")));
            map.put("num",Integer.parseInt((String) map.get("num")));
            map.put("kNum",(Integer)map.get("k")*(Integer)map.get("num"));
        }
        return rootMapperOld.getRootsInfo(map);
    }
    /*添加管理员信息*/
    public boolean addOneRooter(Map<String,Object> map){
        return rootMapperOld.insertOneRoot(map);
    }

    /*修改管理员信息*/
    public boolean updateRooterInfo(Map<String,Object> map){
        return  rootMapperOld.updateRootByInfo(map);
    }

    /*修改管理员信息*/
    public boolean updateRootById(Map<String,Object> map){
        /*检测是否含有rId信息*/
        if (map.containsKey("rId")&&map.size()>1){
            /*将rId转换为整形*/
            map.put("rId",Integer.parseInt((String)map.get("rId")));
            return rootMapperOld.updateRootById(map);
        }else {
            return false;
        }
    }

    /*根据ID删除管理员信息*/
    public boolean deleteOneRooterById(Map<String,Object> map){
        return rootMapperOld.deleteRootByInfoById(map);
    }



}
